package kg.aibek.preuler1;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class Problem3 {
	public void largestPrime() {
		long number = 600851475143L;
		List<Long> primeFactors = getPrimeFactors(number);

		Collections.sort(primeFactors);
		System.out.println(primeFactors.get(primeFactors.size() - 1));
	}

	public List<Long> getPrimeFactors(long number) {
		List<Long> list = new ArrayList<Long>();

		for (long i = 2; i * i <= number; i++) {
			if (number % i == 0) {
				list.add(i);
				list.addAll(getPrimeFactors(number / i));
				return list;
			}
		}
		list.add(number);
		return list;
	}

	public static void main(String[] args) {
		Problem3 p = new Problem3();
		p.largestPrime();
	}
}
